package com.onedec.menu.service.impl;

import com.onedec.menu.dao.OnedecDeptPermissionDao;
import com.onedec.menu.entity.OnedecDeptPermission;
import com.onedec.menu.entity.OnedecDeptPermissionExample;
import com.onedec.menu.service.DeptPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class DeptPermissionServiceImpl implements DeptPermissionService {
    @Autowired
    private OnedecDeptPermissionDao onedecDeptPermissionDao;
    @Override
    public List<OnedecDeptPermission> selectPermissionByDeptid(int id) {
        OnedecDeptPermissionExample example = new OnedecDeptPermissionExample();
        OnedecDeptPermissionExample.Criteria or = example.or();
        or.andDeptIdEqualTo(id);
        return onedecDeptPermissionDao.selectByExample(example);
    }

    @Override
    public void insert(OnedecDeptPermission onedecDeptPermission) {
        onedecDeptPermissionDao.insertSelective(onedecDeptPermission);
    }

    @Override
    public List<OnedecDeptPermission> selectByDeptIdAndPermissionId(int deptId, int permissionId) {
        OnedecDeptPermissionExample example = new OnedecDeptPermissionExample();
        OnedecDeptPermissionExample.Criteria or = example.or();
        or.andDeptIdEqualTo(deptId);
        or.andPermissionIdEqualTo(permissionId);
        return onedecDeptPermissionDao.selectByExample(example);
    }

    @Override
    public void delete(int deptId) {
        OnedecDeptPermissionExample example = new OnedecDeptPermissionExample();
        OnedecDeptPermissionExample.Criteria or = example.or();
        or.andDeptIdEqualTo(deptId);
        onedecDeptPermissionDao.deleteByExample(example);
    }
}
